package Hot100.Tree;

import java.util.ArrayList;
import java.util.List;

public class kthSmallest {
    public static void main(String[] args) {
        int[] value = {3,1,4,-1,2};
        BinaryTree binaryTree = new BinaryTree();
        binaryTree.insert(value);
        int k = 1;
        System.out.println(new kthSmallest().kthSmallest(binaryTree.root,k));
    }
    List<Integer> list = new ArrayList<>();
    public int kthSmallest(TreeNode root, int k) {
        if (root == null)
            return -1;
        inorder(root);

        return list.get(k-1);
    }

    public void inorder(TreeNode root){
        if(root == null)
            return;
        inorder(root.left);
        list.add(root.val);
        inorder(root.right);
    }
}
